home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Scope / Scope Disk #142 (199x)(Scope PD)(US)[WB].zip / Scope Disk #142 (199x)(Scope PD)(US)[WB].adf / Decigel1.02 / decigel020.asm < prev    next >
Assembly Source File  |  1990-07-30  |  3KB  |  140 lines

  1. **
  2. **
  3. **  Decigel020    - The functionality of the famous "decigel" program, but
  4. **  working on the 68020/68030 processors.
  5. **
  6. **  The old Decigel would correctly patch the instruction on the 68020,
  7. **  but chances are the old (bad) instruction was still in the instruction
  8. **  cache.  This code flushes the cache after modifying memory.
  9. **
  10. **  This code may not function under future revisions of the operating
  11. **  system.  This code is safe on the 68000/68010/68020 and 68030.
  12. **  This code is not expected to function on the 68040.
  13. **
  14. **
  15. **  Written Tuesday 03-Apr-90 21:21:47 -Bryce Nesbitt
  16. **
  17. **
  18.         INCLUDE "exec/types.i"
  19.         INCLUDE "exec/memory.i"
  20.         INCLUDE "exec/ables.i"
  21.         INCLUDE "exec/execbase.i"
  22.         INCLUDE "libraries/dosextens.i"
  23.  
  24.         INT_ABLES
  25.  
  26.         XREF    _LVOFindTask
  27.         XREF    _LVOSupervisor
  28.  
  29. ABSEXECBASE    EQU 4
  30. PrivTrapVector    EQU $20
  31.  
  32.  
  33.  
  34.  
  35. ;-------------- install patch then detach -----------------------------------
  36.  
  37.         move.l    ABSEXECBASE,a6
  38.  
  39.  
  40.         ;
  41.         ;   Contents of the old vector are used to self-modify our
  42.         ;   code.  The new vector replaces the old.
  43.         ;
  44.         DISABLE
  45.         move.l    PrivTrapVector,ModifyCode+2
  46.         bsr.s    FlushCache
  47.         move.l    #NewPrivTrap,PrivTrapVector
  48.         ENABLE
  49.  
  50.  
  51.         ;
  52.         ;   Detach our code from the CLI
  53.         ;
  54.         suba.l    a1,a1
  55.         jsr    _LVOFindTask(a6)
  56.         move.l    d0,a0
  57.         move.l    pr_CLI(a0),a0
  58.         add.l    a0,a0
  59.         add.l    a0,a0
  60.         move.l    a0,d0
  61.         beq.s    not_cli
  62.         clr.l    cli_Module(a0)
  63. not_cli:    moveq    #0,d0
  64.         rts
  65.  
  66.  
  67.  
  68.  
  69. *
  70. *   Flush the instruction cache
  71. *
  72. FlushCache:    movem.l a5/a6,-(sp)
  73.         move.l    ABSEXECBASE,a6
  74.         btst.b    #AFB_68020,AttnFlags+1(a6)  ;>=68020 includes cache
  75.         beq.s    fc_nocache
  76.  
  77.         lea.l    FlushTrap(pc),a5
  78.         jsr    _LVOSupervisor(a6)
  79.  
  80. fc_nocache:    movem.l (sp)+,a5/a6
  81.         rts
  82. ;
  83. ;
  84. FlushTrap:    dc.w    $4e7a,$0002 ;movec.l CACR,d0
  85.         bset    #3,d0        ;Set "Clear instruction cache" bit
  86.         dc.w    $4e7b,$0002 ;movec.l d0,CACR
  87.         rte
  88.  
  89.  
  90.  
  91.  
  92.  
  93. *****************************************************************************
  94. **                                       **
  95. **                                       **
  96. **  The trap handler wedged into the privilege violation vector.       **
  97. **                                       **
  98. **  If the instruction was MOVE SR,<ea> it is converted to MOVE CCR,<ea>.  **
  99. **  The instruction cache is flushed, then the instruction is re-executed. **
  100. **                                       **
  101. **                                       **
  102. *****************************************************************************
  103.  
  104. STKOFFSET    EQU    4*3
  105.  
  106. ;
  107. ;   New privilege violation vector
  108. ;
  109. NewPrivTrap:    movem.l d0/a0/a6,-(sp)
  110.         move.l    STKOFFSET+2(sp),a0
  111.         move.w    (a0),d0             ; Examine opcode
  112.         andi.w    #~%111111,d0        ; Mask out EA field
  113.         cmpi.w    #$40C0,d0        ; A MOVE SR,<ea>?
  114.         beq.s    GotOne
  115.         movem.l (sp)+,d0/a0/a6
  116. ModifyCode:    jmp    $01234567        ; To previous handler... (exit)
  117.  
  118. ;
  119. ;   Code executed if the instruction was MOVE SR,<ea>
  120. ;
  121. GotOne:     move.l    ABSEXECBASE,a6
  122.  
  123.  
  124.         DISABLE
  125.         bset    #1,(a0)             ; Convert to MOVE CCR,<ea>
  126.         btst.b    #AFB_68020,AttnFlags+1(a6)  ;>=68020 includes cache
  127.         beq.s    no_cache
  128.  
  129.         dc.w    $4e7b,$8802 ; movec.l a0,CAAR
  130.         dc.w    $4e7a,$0002 ; movec.l CACR,d0
  131.         bset    #2,d0        ; Set "Clear entry in instruction cache"
  132.         dc.w    $4e7b,$0002 ; movec.l d0,CACR
  133. no_cache:    ENABLE
  134.  
  135.  
  136.         movem.l (sp)+,d0/a0/a6
  137.         rte                ; Rerun new opcode... (exit)
  138.  
  139.     END
  140.